package com.ruoyi.bantong.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bantong.domain.BtUserTicket;
import com.ruoyi.bantong.service.IBtUserTicketService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户奖券Controller
 * 
 * @author laohei
 * @date 2021-01-27
 */
@RestController
@RequestMapping("/bantong/ticket")
public class BtUserTicketController extends BaseController
{
    @Autowired
    private IBtUserTicketService btUserTicketService;

    /**
     * 查询用户奖券列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:list')")
    @GetMapping("/list")
    public TableDataInfo list(BtUserTicket btUserTicket)
    {
        if(btUserTicket.getUserId() == null){
            btUserTicket.setUserId(SecurityUtils.getBtUserId());
        }
        startPage();
        List<BtUserTicket> list = btUserTicketService.selectBtUserTicketList(btUserTicket);
        return getDataTable(list);
    }

    /**
     * 导出用户奖券列表
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:export')")
    @Log(title = "用户奖券", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BtUserTicket btUserTicket)
    {
        List<BtUserTicket> list = btUserTicketService.selectBtUserTicketList(btUserTicket);
        ExcelUtil<BtUserTicket> util = new ExcelUtil<BtUserTicket>(BtUserTicket.class);
        return util.exportExcel(list, "ticket");
    }

    /**
     * 获取用户奖券详细信息
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:query')")
    @GetMapping(value = "/{utId}")
    public AjaxResult getInfo(@PathVariable("utId") Integer utId)
    {
        return AjaxResult.success(btUserTicketService.selectBtUserTicketById(utId));
    }

    /**
     * 新增用户奖券
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:add')")
    @Log(title = "用户奖券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BtUserTicket btUserTicket)
    {
        return toAjax(btUserTicketService.insertBtUserTicket(btUserTicket));
    }

    /**
     * 修改用户奖券
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:edit')")
    @Log(title = "用户奖券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BtUserTicket btUserTicket)
    {
        return toAjax(btUserTicketService.updateBtUserTicket(btUserTicket));
    }

    /**
     * 删除用户奖券
     */
    //@PreAuthorize("@ss.hasPermi('bantong:ticket:remove')")
    @Log(title = "用户奖券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{utIds}")
    public AjaxResult remove(@PathVariable Integer[] utIds)
    {
        return toAjax(btUserTicketService.deleteBtUserTicketByIds(utIds));
    }
}
